package com.ylsf.blog.controller;

import com.ylsf.blog.pojo.Article;
import com.ylsf.blog.service.UpdateService;
import com.ylsf.blog.service.impl.UpdateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * 文章修改控制类
 */
@WebServlet("/updateArticle")
public class UpdateServlet extends HttpServlet {
    private UpdateService updateService=new UpdateServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("utf-8");
        //获取文章Id
        String articleId = request.getParameter("articleId");
        //获取文章标题
        String title = request.getParameter("title");
        //获取文章内容
        String context = request.getParameter("context");
        //获取文章作者
        String author = request.getParameter("author");
        //获取文章发布时间
        String date = request.getParameter("date");
        Date date1 = new Date(date);
        Article article=new Article(Integer.valueOf(articleId),title,context,date1,author);
        System.out.println("///////////");
        boolean flag = updateService.updateArticle(article);
        if(flag){
            response.getWriter().print("修改成功");
        }else {
            response.getWriter().print("修改失败");
        }

    }
}
